<template>
  <div class="home">
    <div class="nav">
      <div class="list">
        <span class="all"  v-show="isShow">全部</span>
        <ul :style="{left:toLeft+'px'}"  v-show="!isShow">
          <router-link tag="li" to="/home/recommend">推荐</router-link>
          <router-link tag="li" to="/home/phone">手机</router-link>
          <router-link tag="li" to="/home/ai">智能</router-link>
          <router-link tag="li" to="/home/tv">电视</router-link>
          <router-link tag="li" to="/home/laptop">笔记本</router-link>
          <router-link tag="li" to="/home/appliances">家电</router-link>
          <router-link tag="li" to="/home/around">生活周边</router-link>
        </ul>
      </div>
      <div class="list2" v-show="isShow">
        <router-link tag="span" to="/home/recommend" active-class="router" @click.native="changeShow">推荐</router-link>
        <router-link tag="span" to="/home/phone" active-class="router" @click.native="changeShow">手机</router-link>
        <router-link tag="span" to="/home/ai" active-class="router" @click.native="changeShow">智能</router-link>
        <router-link tag="span" to="/home/tv" active-class="router" @click.native="changeShow">电视</router-link>
        <router-link tag="span" to="/home/laptop" active-class="router" @click.native="changeShow">笔记本</router-link>
        <router-link tag="span" to="/home/appliances" active-class="router" @click.native="changeShow">家电</router-link>
        <router-link tag="span" to="/home/around" active-class="router" @click.native="changeShow">生活周边</router-link>
      </div>
      <span class="iconfont icon-jiantou-copy-copy" @click="rotate" ref="arrow"></span>
    </div>
    <router-view></router-view>
  </div>
</template>

<script>
// @ is an alias to /src
export default {
  data() {
    return {
      toLeft: 0,
      state: 0,
      isShow:false
    }
  },
  name: "Home",
  methods: {
    rotate() {
      if (this.state == 0) {
        this.$refs.arrow.style.transform = "rotateZ(180deg)";
        this.state = 1;
        this.isShow = true;
      } else {
        this.$refs.arrow.style.transform = "rotateZ(0deg)";
        this.state = 0;
        this.isShow = false;
      }
    },
    changeShow(){
      this.$refs.arrow.style.transform = "rotateZ(0deg)";
      this.state = 0;
      this.isShow = false;
    }
  },
  watch: {
    $route(to, from) {
      if (to.meta.order < 7) {
        if (to.meta.order > 4 && to.meta.order > from.meta.order) {
          this.toLeft -= 45;
        }
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.home {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.nav {
  display: flex;
  position: relative;
  .list {
    flex: 1;
    flex-wrap: nowrap;
    overflow: hidden;
    position: relative;
    .all {
      position: absolute;
      left: 15px;
    }
    ul {
      position: absolute;
      white-space: nowrap;
      transition: all 0.5s;
      li {
        line-height: 30px;
        height: 30px;
        font-size: 14px;
        color: rgb(116, 116, 116);
        margin: 0 12px;
        list-style: none;
        display: inline-block;
      }
    }
  }
  .router-link-active {
    color: #ee752a;
    border-bottom: 3px solid #ed5b00;
  }
  span {
    line-height: 30px;
    height: 30px;
    font-size: 14px;
    color: rgb(116, 116, 116);
  }
  .iconfont {
    line-height: 30px;
    height: 30px;
    font-size: 14px;
    color: rgb(116, 116, 116);
    width: 30px;
    background: #f3f3f3;
    text-align: center;
    margin: 0 10px;
    transition: all 0.5s;
  }
  .list2 {
    position: absolute;
    top: 32px;
    left: 0;
    z-index: 1;
    background: #f2f2f2;
    padding-top: 10px;
    span {
      width: 79px;
      height: 30px;
      display: inline-block;
      border: 1px solid #e5e5e5;
      color: #5e5e5e;
      margin: 0 7px;
      box-sizing: border-box;
      background: white;
      border-radius: 3px;
      margin-bottom: 10px;
      text-align: center;
      font-size: 12px;
    }
    .router {
      background-color: #fde0d5;
      border-color: #ff6700;
      color: #ff6700;
    }
  }
}
</style>